import InitForm from '../InitForm';
import { Drawer } from 'antd';
import React, { useState, memo } from 'react';
import DetailPro from '../DetailPro';
import PropTypes from 'prop-types';

function DrawerPro(props) {
  let newProps = { ...props };
  delete newProps.children;

  const detailprops = {
    title: props.title,
    detailpath: props.detailpath,
    fields: props.fields,
    detailData: props.detailData,
    params: props.params,
  };
  const fields = newProps?.fields?.filter?.((it, i) => {
    return it?.valueType != 'option';
  });
  return (
    <Drawer
      maskClosable={false}
      placement="right"
      closable={true}
      width={'100%'}
      destroyOnClose={true}
      {...props}
    >
      {props.val === 'only' && props.children}
      {props.val === 'only' ? null : props.val === 'detail' ? (
        <DetailPro {...detailprops} />
      ) : (
        <InitForm {...newProps} fields={fields} />
      )}
    </Drawer>
  );
}

DrawerPro.propTypes = {
  detailpath: PropTypes.string, //详情
  params: PropTypes.object, //详情｜表单编辑 参数
  fields: PropTypes.array, //详情列表
  detailData: PropTypes.object, //详情数据
};

export default DrawerPro;
